<template>
  <div class="layout-padding">
    <!-- 设备列表清单 -->
    <el-card shadow="hover" class="layout-padding-auto">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="待维修工单" name="1">
          <div style="display: flex; flex-wrap: wrap">
            <div class="sreachItem">
              <el-input
                style="width: 95%"
                v-model="search.keyword"
                placeholder="可输入设备编号、名称、工单号、姓名"
              />
            </div>
            <div class="sreachItem">
              <span style="margin-right: 5px">故障等级</span>
              <el-select
                v-model="search.failureLevelId"
                class="m-2"
                placeholder="故障等级"
              >
                <el-option
                  v-for="item in failureLevels"
                  :key="item.id"
                  :label="item.configValue"
                  :value="item.id"
                />
              </el-select>
            </div>
            <div class="sreachItem">
              <span style="margin-right: 5px">维修状态</span>
              <el-select
                v-model="search.repairStatus"
                class="m-2"
                placeholder="维修状态"
              >
                <el-option label="全部" value="" />
                <el-option label="待维修" value="1" />
                <el-option label="维修中" value="2" />
                <el-option label="待验证" value="3" />
                <el-option label="关闭-待验证" value="4" />
              </el-select>
            </div>
            <div class="sreachItem">
              <span style="margin-right: 5px">维修类型</span>
              <el-select
                v-model="search.repairType"
                class="m-2"
                placeholder="维修类型"
              >
                <el-option label="全部" value="" />
                <el-option label="内部维修" value="1" />
                <el-option label="委外维修" value="2" />
              </el-select>
            </div>
            <div class="sreachItem">
              <span style="margin-right: 5px">报修来源</span>
              <el-select
                v-model="search.source"
                class="m-2"
                placeholder="报修来源"
              >
                <el-option label="全部" value="" />
                <el-option label="正常报修" value="1" />
                <el-option label="维保报修" value="2" />
                <el-option label="点检报修" value="3" />
              </el-select>
            </div>
          </div>
          <div
            style="
              display: flex;
              justify-content: space-between;
              margin: 10px 0;
            "
          >
            <div>
              <el-button type="primary" @click="searchFor">搜索</el-button>
              <el-button type="primary" plain @click="resetFor">重置</el-button>
            </div>
            <div>
              <el-button
                type="primary"
                @click="repairApplication"
                v-if="buttonDisplayOrNot(buttonCodes, 'wxRepairReportBtn')"
                >报修</el-button
              >
              <el-button
                type="primary"
                plain
                @click="subcontracting"
                v-if="buttonDisplayOrNot(buttonCodes, 'wxOutsourcingBtn')"
                >委外维修</el-button
              >
              <el-button
                type="primary"
                plain
                @click="batchTransmit"
                v-if="buttonDisplayOrNot(buttonCodes, 'wxBatchTransmitBtn')"
                >批量转交</el-button
              >
              <el-button
                type="primary"
                plain
                @click="transmitRecord"
                v-if="buttonDisplayOrNot(buttonCodes, 'wxTransmitRecordBtn')"
                >转交记录</el-button
              >
            </div>
          </div>
          <Table
            ref="tableRef"
            v-bind="state.tableData"
            class="table-demo"
            @delRow="onTableDelRow"
            @pageChange="onTablePageChange"
            @listenClick="listenClick"
          >
            <template #default="{ slotData, slotColumn }">
              <div v-if="slotColumn.key === 'repairType'">
                {{ slotData.repairType == 1 ? '内部维修' : '委外维修' }}
              </div>
              <div v-if="slotColumn.key === 'source'">
                {{
                  slotData.source == 1
                    ? '正常报修'
                    : slotData.source == 2
                    ? '维保报修'
                    : '点检报修'
                }}
              </div>
              <div v-if="slotColumn.key === 'repairStatus'">
                <span v-if="slotData.repairStatus == 9">
                  维修关闭
                  <el-popover
                    placement="top-start"
                    title="关闭原因"
                    :width="200"
                    trigger="hover"
                    :content="slotData.closeReason"
                  >
                    <template #reference>
                      <svg
                        t="1681107624752"
                        class="icon"
                        viewBox="0 0 1024 1024"
                        version="1.1"
                        xmlns="http://www.w3.org/2000/svg"
                        p-id="3558"
                        width="20"
                        height="20"
                      >
                        <path
                          d="M976.738462 704.984615c27.569231-63.015385 39.384615-129.969231 39.384615-196.923077s-11.815385-133.907692-39.384615-196.923076S913.723077 196.923077 866.461538 149.661538c-47.261538-47.261538-102.4-82.707692-161.476923-110.276923-63.015385-27.569231-129.969231-39.384615-196.923077-39.384615s-133.907692 11.815385-196.923076 39.384615S196.923077 102.4 149.661538 149.661538 66.953846 248.123077 39.384615 311.138462c-27.569231 63.015385-39.384615 129.969231-39.384615 196.923076s11.815385 133.907692 39.384615 196.923077c27.569231 59.076923 63.015385 114.215385 110.276923 161.476923 47.261538 47.261538 102.4 82.707692 161.476924 110.276924 63.015385 27.569231 129.969231 39.384615 196.923076 39.384615s133.907692-11.815385 196.923077-39.384615c59.076923-27.569231 114.215385-63.015385 161.476923-110.276924 47.261538-47.261538 82.707692-98.461538 110.276924-161.476923z m-31.507693-196.923077c0 59.076923-11.815385 114.215385-35.446154 169.353847-23.630769 51.2-55.138462 98.461538-94.523077 137.846153s-86.646154 70.892308-137.846153 94.523077c-55.138462 23.630769-110.276923 35.446154-169.353847 35.446154s-114.215385-11.815385-169.353846-35.446154c-51.2-23.630769-98.461538-55.138462-137.846154-94.523077s-70.892308-86.646154-94.523076-137.846153c-23.630769-55.138462-35.446154-110.276923-35.446154-169.353847s11.815385-114.215385 35.446154-169.353846C126.030769 283.569231 157.538462 240.246154 200.861538 196.923077c39.384615-39.384615 86.646154-70.892308 137.846154-94.523077 55.138462-23.630769 110.276923-35.446154 169.353846-35.446154s114.215385 11.815385 169.353847 35.446154c55.138462 23.630769 98.461538 55.138462 141.784615 94.523077 39.384615 39.384615 70.892308 86.646154 94.523077 137.846154 19.692308 59.076923 31.507692 114.215385 31.507692 173.292307z"
                          fill="#C2C2C2"
                          p-id="3559"
                        ></path>
                        <path
                          d="M508.061538 153.6c-47.261538 0-90.584615 39.384615-90.584615 90.584615s39.384615 90.584615 90.584615 90.584616 90.584615-39.384615 90.584616-90.584616-43.323077-90.584615-90.584616-90.584615zM464.738462 823.138462c3.938462 7.876923 3.938462 11.815385 11.815384 15.753846 3.938462 3.938462 7.876923 7.876923 15.753846 11.815384 7.876923 3.938462 11.815385 3.938462 19.692308 3.938462h7.876923c3.938462 0 7.876923 0 7.876923-3.938462 3.938462 0 3.938462-3.938462 7.876923-3.938461 3.938462-3.938462 3.938462-3.938462 7.876923-3.938462 0-3.938462 3.938462-3.938462 3.938462-7.876923s3.938462-3.938462 3.938461-7.876923 3.938462-3.938462 3.938462-7.876923v-7.876923h-47.261539 47.261539v-354.461539-7.876923c0-3.938462 0-7.876923-3.938462-7.876923 0-3.938462-3.938462-3.938462-3.938461-7.876923s-3.938462-3.938462-3.938462-7.876923c-3.938462 0-3.938462-3.938462-7.876923-3.938461s-3.938462-3.938462-7.876923-3.938462-3.938462-3.938462-7.876923-3.938461H512h-7.876923c-3.938462 0-7.876923 0-7.876923 3.938461-3.938462 0-3.938462 3.938462-7.876923 3.938462-3.938462 3.938462-3.938462 3.938462-7.876923 3.938461 0 3.938462-3.938462 3.938462-3.938462 7.876923s-3.938462 3.938462-3.938461 7.876923-3.938462 7.876923-3.938462 7.876923v7.876923h47.261539-47.261539v354.461539c-7.876923 0-7.876923 3.938462-3.938461 11.815385z"
                          fill="#C2C2C2"
                          p-id="3560"
                        ></path>
                      </svg>
                    </template>
                  </el-popover>
                </span>
                <span v-else>
                  {{
                    slotData.repairStatus == 1
                      ? '待维修'
                      : slotData.repairStatus == 2
                      ? '维修中'
                      : slotData.repairStatus == 3
                      ? '待验证'
                      : slotData.repairStatus == 4
                      ? '关闭-待验证'
                      : slotData.repairStatus == 5
                      ? '维修完成'
                      : ''
                  }}
                </span>
              </div>
            </template>
          </Table>
        </el-tab-pane>
        <el-tab-pane label="已维修工单" name="2">
          <TableSearch
            :search="state.search2"
            @search="onSearch2"
            @listenClick="listenClick2"
          />
          <Table
            ref="tableRef"
            v-bind="state.tableData2"
            class="table-demo"
            @delRow="onTableDelRow2"
            @pageChange="onTablePageChange2"
            @listenClick="listenClick2"
            @dataList="dataList"
          >
            <template #default="{ slotData, slotColumn }">
              <div v-if="slotColumn.key === 'repairType'">
                {{ slotData.repairType == 1 ? '内部维修' : '委外维修' }}
              </div>
              <div v-if="slotColumn.key === 'source'">
                {{
                  slotData.source == 1
                    ? '正常报修'
                    : slotData.source == 2
                    ? '维保报修'
                    : slotData.source == 3
                    ? '点检报修'
                    : ''
                }}
              </div>
              <div v-if="slotColumn.key === 'repairFee'">
                {{ slotData.repairFee + slotData.outsourceFee }}
              </div>
              <div v-if="slotColumn.key === 'repairStatus'">
                {{
                  slotData.repairStatus == 1
                    ? '待维修'
                    : slotData.repairStatus == 2
                    ? '维修中'
                    : slotData.repairStatus == 3
                    ? '待验证'
                    : slotData.repairStatus == 4
                    ? '关闭-待验证'
                    : slotData.repairStatus == 5
                    ? '维修完成'
                    : slotData.repairStatus == 9
                    ? '维修关闭'
                    : ''
                }}
                <el-popover
                  v-if="slotData.repairStatus == 9"
                  placement="top-start"
                  title="关闭维修原因"
                  :width="200"
                  trigger="hover"
                  :content="slotData.closeReason"
                >
                  <template #reference>
                    <svg
                      t="1678764409917"
                      class="icon"
                      viewBox="0 0 1024 1024"
                      version="1.1"
                      xmlns="http://www.w3.org/2000/svg"
                      p-id="3361"
                      width="20"
                      height="20"
                    >
                      <path
                        d="M976.738462 704.984615c27.569231-63.015385 39.384615-129.969231 39.384615-196.923077s-11.815385-133.907692-39.384615-196.923076S913.723077 196.923077 866.461538 149.661538c-47.261538-47.261538-102.4-82.707692-161.476923-110.276923-63.015385-27.569231-129.969231-39.384615-196.923077-39.384615s-133.907692 11.815385-196.923076 39.384615S196.923077 102.4 149.661538 149.661538 66.953846 248.123077 39.384615 311.138462c-27.569231 63.015385-39.384615 129.969231-39.384615 196.923076s11.815385 133.907692 39.384615 196.923077c27.569231 59.076923 63.015385 114.215385 110.276923 161.476923 47.261538 47.261538 102.4 82.707692 161.476924 110.276924 63.015385 27.569231 129.969231 39.384615 196.923076 39.384615s133.907692-11.815385 196.923077-39.384615c59.076923-27.569231 114.215385-63.015385 161.476923-110.276924 47.261538-47.261538 82.707692-98.461538 110.276924-161.476923z m-31.507693-196.923077c0 59.076923-11.815385 114.215385-35.446154 169.353847-23.630769 51.2-55.138462 98.461538-94.523077 137.846153s-86.646154 70.892308-137.846153 94.523077c-55.138462 23.630769-110.276923 35.446154-169.353847 35.446154s-114.215385-11.815385-169.353846-35.446154c-51.2-23.630769-98.461538-55.138462-137.846154-94.523077s-70.892308-86.646154-94.523076-137.846153c-23.630769-55.138462-35.446154-110.276923-35.446154-169.353847s11.815385-114.215385 35.446154-169.353846C126.030769 283.569231 157.538462 240.246154 200.861538 196.923077c39.384615-39.384615 86.646154-70.892308 137.846154-94.523077 55.138462-23.630769 110.276923-35.446154 169.353846-35.446154s114.215385 11.815385 169.353847 35.446154c55.138462 23.630769 98.461538 55.138462 141.784615 94.523077 39.384615 39.384615 70.892308 86.646154 94.523077 137.846154 19.692308 59.076923 31.507692 114.215385 31.507692 173.292307z"
                        fill="#C2C2C2"
                        p-id="3362"
                      ></path>
                      <path
                        d="M508.061538 153.6c-47.261538 0-90.584615 39.384615-90.584615 90.584615s39.384615 90.584615 90.584615 90.584616 90.584615-39.384615 90.584616-90.584616-43.323077-90.584615-90.584616-90.584615zM464.738462 823.138462c3.938462 7.876923 3.938462 11.815385 11.815384 15.753846 3.938462 3.938462 7.876923 7.876923 15.753846 11.815384 7.876923 3.938462 11.815385 3.938462 19.692308 3.938462h7.876923c3.938462 0 7.876923 0 7.876923-3.938462 3.938462 0 3.938462-3.938462 7.876923-3.938461 3.938462-3.938462 3.938462-3.938462 7.876923-3.938462 0-3.938462 3.938462-3.938462 3.938462-7.876923s3.938462-3.938462 3.938461-7.876923 3.938462-3.938462 3.938462-7.876923v-7.876923h-47.261539 47.261539v-354.461539-7.876923c0-3.938462 0-7.876923-3.938462-7.876923 0-3.938462-3.938462-3.938462-3.938461-7.876923s-3.938462-3.938462-3.938462-7.876923c-3.938462 0-3.938462-3.938462-7.876923-3.938461s-3.938462-3.938462-7.876923-3.938462-3.938462-3.938462-7.876923-3.938461H512h-7.876923c-3.938462 0-7.876923 0-7.876923 3.938461-3.938462 0-3.938462 3.938462-7.876923 3.938462-3.938462 3.938462-3.938462 3.938462-7.876923 3.938461 0 3.938462-3.938462 3.938462-3.938462 7.876923s-3.938462 3.938462-3.938461 7.876923-3.938462 7.876923-3.938462 7.876923v7.876923h47.261539-47.261539v354.461539c-7.876923 0-7.876923 3.938462-3.938461 11.815385z"
                        fill="#C2C2C2"
                        p-id="3363"
                      ></path>
                    </svg>
                  </template>
                </el-popover>
              </div>
            </template>
          </Table>
        </el-tab-pane>
      </el-tabs>
      <RepairApplication
        :dialogVisible="dialogVisible"
        @cancelRepair="cancelRepair"
        @submitRepair="submitRepair"
      ></RepairApplication>
      <CloseRepair
        :closeDialog="closeDialog"
        :closeId="closeId"
        @closeCancel="closeCancel"
        @closeSubmit="closeSubmit"
      ></CloseRepair>
      <TransmitTaskDialog
        :addDialog="transmitDialog"
        :primaryForm="primaryForm"
        @addCancel="closeTransmit"
        @addSubmit="submitTransmit"
      >
      </TransmitTaskDialog>
      <MoreTransmitTaskDialog
        :addDialog="transmitMoreDialog"
        :primaryForm="primaryMoreForm"
        @addCancel="closeMoreTransmit"
        @addSubmit="submitMoreTransmit"
      >
      </MoreTransmitTaskDialog>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, watch, reactive, onMounted, defineAsyncComponent } from 'vue'
import { ElMessage, ElMessageBox, TabsPaneContext } from 'element-plus'
import router from '/@/router'
import { deleteRepairApi, repairBatchReportApi } from '/@/api/repair'
import { dictionaryList } from '/@/api/publicApi'
import { useRoute } from 'vue-router'
import { buttonDisplayOrNot } from '../../utils/buttonBoolean'
import { getButtonListByRoleApi } from '/@/api/publicApi'
import { Session } from '/@/utils/storage'
const menu = Session.get('menu')
const buttonCodes = ref<any>([])
const Table = defineAsyncComponent(
  () => import('/@/components/table/index.vue')
)
const TableSearch = defineAsyncComponent(
  () => import('/@/components/table/search.vue')
)
const RepairApplication = defineAsyncComponent(
  () => import('./components/RepairApplication.vue')
)
const CloseRepair = defineAsyncComponent(
  () => import('./components/CloseRepair.vue')
)
const TransmitTaskDialog = defineAsyncComponent(
  () => import('./components/TransmitTaskDialog.vue')
)
const MoreTransmitTaskDialog = defineAsyncComponent(
  () => import('./components/MoreTransmitTaskDialog.vue')
)
const route = useRoute()
const dialogVisible = ref<boolean>(false) //弹窗是否出现
const userInfo = Session.get('shebei')
const activeName = ref(route.query.active ? route.query.active : '1')

// 定义变量内容
const tableRef = ref<RefType>()
const state = reactive<TableDemoState>({
  tableData: {
    flash: false, // 刷新表格
    // 表头内容（必传，注意格式）
    header: [
      {
        key: 'repairOrderNum',
        colWidth: '160',
        title: '维修工单号',
        type: 'text'
      },
      { key: 'deviceNum', colWidth: '160', title: '设备编号', type: 'text' },
      { key: 'deviceName', colWidth: '160', title: '设备名称', type: 'text' },
      { key: 'repairType', colWidth: '160', title: '维修类型', type: 'slot' },
      { key: 'repairStatus', colWidth: '160', title: '维修状态', type: 'slot' },
      { key: 'createTime', colWidth: '160', title: '报修时间', type: 'text' },
      { key: 'failureLevel', colWidth: '160', title: '故障等级', type: 'text' },
      {
        key: 'failureCategory',
        colWidth: '160',
        title: '故障类型',
        type: 'text'
      },
      { key: 'createUserName', colWidth: '160', title: '报修人', type: 'text' },
      { key: 'repairUserName', colWidth: '160', title: '维修人', type: 'text' },
      { key: 'verifyUserName', colWidth: '160', title: '验证人', type: 'text' },
      { key: 'source', colWidth: '160', title: '报修来源', type: 'slot' }
    ],
    columnBtn: [
      {
        name: 'detailRepair',
        text: '详情',
        type: 'primary',
        hide(row: any): boolean {
          return true
        },
        btns: buttonCodes.value,
        btnCode: 'wxDetailBtn'
      },
      {
        name: 'closeRepair',
        text: '关闭维修',
        hide(row: any): boolean {
          return row.closeRepairShowFlag == 1 || row.closeRepairShowFlag == 2
        },
        type: 'warning',
        btns: buttonCodes.value,
        btnCode: 'wxCloseRepairBtn'
      },
      {
        name: 'verifyRepair',
        text: '维修验证',
        hide(row: any): boolean {
          return row.verifyShowFlag == 1
        },
        type: 'warning',
        btns: buttonCodes.value,
        btnCode: 'wxVerifyBtn'
      },
      {
        name: 'transmitTask',
        text: '维修转交',
        hide(row: any): boolean {
          return row.repairType == 1
        },
        type: 'warning',
        btns: buttonCodes.value,
        btnCode: 'wxTransmitBtn'
      },
      {
        name: 'entryRepair',
        text: '维修录入',
        hide(row: any): boolean {
          return row.repairEnterShowFlag == 1
        },
        type: 'warning',
        btns: buttonCodes.value,
        btnCode: 'wxEnterBtn'
      },
      {
        name: 'delRepair',
        text: '删除',
        hide(row: any): boolean {
          return row.deleteShowFlag == 1
        },
        type: 'danger',
        btns: buttonCodes.value,
        btnCode: 'wxDeteleBtn'
      }
    ],
    // 配置项（必传）
    config: {
      listApi: '/device/mobile/deviceRepair/repairListByPage',
      listHttp: 'post',
      total: 0, // 列表总数
      loading: true, // loading 加载
      noPage: false, // 是否分页
      isSerialNo: true, // 是否显示表格序号
      isSelection: false, // 是否显示表格多选
      isOperate: true, // 是否显示表格操作栏
      isExtend: false, // 是否可以扩展
      operateName: 'order', //操作栏宽度
      operateWidth: '450', //操作栏宽度
      fixed: 'right' //操作栏固定
    },
    // 搜索参数
    param: {
      type: 1 // 必传参数，分页的不要传
    }
  },
  tableData2: {
    flash: false, // 刷新表格
    // 表头内容（必传，注意格式）
    header: [
      {
        key: 'repairOrderNum',
        colWidth: '160',
        title: '维修工单号',
        type: 'text'
      },
      { key: 'deviceName', colWidth: '160', title: '设备名称', type: 'text' },
      { key: 'deviceNum', colWidth: '160', title: '设备编号', type: 'text' },
      { key: 'repairType', colWidth: '160', title: '维修类型', type: 'slot' },
      { key: 'repairStatus', colWidth: '160', title: '维修状态', type: 'slot' },
      { key: 'createTime', colWidth: '160', title: '报修时间', type: 'text' },
      { key: 'endTime', colWidth: '160', title: '维修完成时间', type: 'text' },
      { key: 'repairFee', colWidth: '160', title: '维修总费用', type: 'slot' },
      { key: 'failureLevel', colWidth: '160', title: '故障等级', type: 'text' },
      {
        key: 'failureCategory',
        colWidth: '160',
        title: '故障类型',
        type: 'text'
      },
      { key: 'createUserName', colWidth: '160', title: '报修人', type: 'text' },
      { key: 'repairUserName', colWidth: '160', title: '维修人', type: 'text' },
      { key: 'verifyUserName', colWidth: '160', title: '验证人', type: 'text' },
      { key: 'source', colWidth: '160', title: '报修来源', type: 'slot' }
    ],
    columnBtn: [
      {
        name: 'detailRepair',
        text: '详情',
        type: 'primary',
        btns: buttonCodes.value,
        btnCode: 'ywxDetailBtn'
      },
      {
        name: 'exportRecords',
        text: '导出记录',
        type: 'primary',
        loading: false,
        btns: buttonCodes.value,
        btnCode: 'ywxExportRecordBtn'
      },
      {
        name: 'delRepair',
        text: '删除',
        hide(row: any): boolean {
          return true
        },
        type: 'danger',
        btns: buttonCodes.value,
        btnCode: 'ywxDeleteBtn'
      },
      {
        name: 'subcontracting2',
        text: '委外维修',
        hide(row: any): boolean {
          return row.outsourceShowFlag == 1
        },
        type: 'primary',
        btns: buttonCodes.value,
        btnCode: 'ywxOutsourcingBtn'
      }
    ],
    // 配置项（必传）
    config: {
      listApi: '/device/mobile/deviceRepair/repairListByPage',
      listHttp: 'post',
      total: 0, // 列表总数
      loading: true, // loading 加载
      noPage: false, // 是否分页
      isSerialNo: true, // 是否显示表格序号
      isSelection: false, // 是否显示表格多选
      isOperate: true, // 是否显示表格操作栏
      isExtend: false, // 是否可以扩展
      operateName: 'order', //操作栏宽度
      operateWidth: '300', //操作栏宽度
      fixed: 'right' //操作栏固定
    },
    // 搜索参数
    param: {
      type: 2 // 必传参数，分页的不要传
    }
  },
  // 搜索表单，动态生成（传空数组时，将不显示搜索，注意格式）
  search2: {
    param: [
      {
        label: '',
        prop: 'keyword',
        placeholder: '可输入设备编号、名称、型号、部门搜索',
        type: 'input'
      },
      {
        label: '时间筛选',
        prop: 'daterange',
        placeholder: '选择时间',
        type: 'daterange'
      },
      {
        label: '故障等级',
        prop: 'failureLevelId',
        placeholder: '故障等级',
        options: [],
        type: 'select'
      },
      {
        label: '维修状态',
        prop: 'repairStatus',
        placeholder: '维修状态',
        options: [
          { configValue: '全部', id: '' },
          { configValue: '完成维修', id: 5 },
          { configValue: '维修关闭', id: 9 }
        ],
        type: 'select'
      },
      {
        label: '维修类型',
        prop: 'repairType',
        placeholder: '维修类型',
        options: [
          { configValue: '全部', id: '' },
          { configValue: '内部维修', id: 1 },
          { configValue: '委外维修', id: 2 }
        ],
        type: 'select'
      },
      {
        label: '报修来源',
        prop: 'source',
        placeholder: '报修来源',
        options: [
          { configValue: '全部', id: '' },
          { configValue: '正常报修', id: 1 },
          { configValue: '维保报修', id: 2 },
          { configValue: '点检报修', id: 3 }
        ],
        type: 'select'
      }
    ],
    btn: [
      {
        text: '批量导出',
        fun: 'batchExport',
        disable: false,
        loading: false,
        type: 'primary',
        hide(): boolean {
          return false
        },
        btns: buttonCodes.value,
        btnCode: 'ywxBatchExportBtn'
      }
    ],
    reset: true
  }
})

const search = ref({
  keyword: '',
  failureLevelId: '',
  repairStatus: '',
  repairType: '',
  source: ''
})

const searchFor = () => {
  state.tableData.param = Object.assign({}, state.tableData.param, {
    ...search.value
  })
  state.tableData.flash = !state.tableData.flash
}

const resetFor = () => {
  search.value.keyword = ''
  search.value.failureLevelId = ''
  search.value.repairStatus = ''
  search.value.repairType = ''
  search.value.source = ''
  searchFor()
}

//获取故障等级
const failureLevels = ref<any>([])
const getrepairLevel = () => {
  dictionaryList({ configType: 'failure_level' }).then((res) => {
    if (res.code == 0) {
      failureLevels.value = res.data
      failureLevels.value.unshift({
        configValue: '全部',
        customizeFlag: 0,
        id: '',
        parentId: ''
      })
      state.search2.param.forEach((item: any) => {
        if (item.prop == 'failureLevelId') {
          item.options = failureLevels.value
        }
      })
    }
  })
}
getrepairLevel()
// 初始化列表数据
const getTableData = () => {
  state.tableData.flash = !state.tableData.flash
}

// 删除当前项回调
const onTableDelRow = (row: EmptyObjectType) => {
  ElMessage.success(`删除${row.name}成功！`)
  getTableData()
}
// 分页改变时回调
const onTablePageChange = (page: TableDemoPageType) => {
  state.tableData.param.pageNum = page.pageNum
  state.tableData.param.pageSize = page.pageSize
  getTableData()
}
// 初始化列表数据
const getTableData2 = () => {
  state.tableData2.flash = !state.tableData2.flash
}

const list = ref([])
const dataList = (val: any) => {
  list.value = val.records
}
// 搜索点击时表单回调
const daochuObj = ref({
  repairStatus: '',
  failureLevelId: '',
  endTime: '',
  startTime: '',
  keyword: '',
  source: '',
  repairType: '',
  type: 2
})
const onSearch2 = (data: EmptyObjectType) => {
  state.tableData2.param = Object.assign({}, state.tableData2.param, {
    ...data
  })
  if (
    state.tableData2.param.daterange &&
    state.tableData2.param.daterange.length != 0
  ) {
    state.tableData2.param.startTime = state.tableData2.param.daterange[0]
    state.tableData2.param.endTime = state.tableData2.param.daterange[1]
  } else {
    state.tableData2.param.startTime = ''
    state.tableData2.param.endTime = ''
  }
  daochuObj.value.repairStatus = data.repairStatus ? data.repairStatus : ''
  daochuObj.value.failureLevelId = data.failureLevelId
    ? data.failureLevelId
    : ''
  daochuObj.value.startTime = data.daterange ? data.daterange[0] : ''
  daochuObj.value.endTime = data.daterange ? data.daterange[1] : ''
  daochuObj.value.keyword = data.keyword ? data.keyword : ''
  daochuObj.value.source = data.source ? data.source : ''
  daochuObj.value.repairType = data.repairType ? data.repairType : ''
  state.tableData2.flash = !state.tableData2.flash
}
// 删除当前项回调
const onTableDelRow2 = (row: EmptyObjectType) => {
  ElMessage.success(`删除${row.name}成功！`)
  getTableData2()
}
// 分页改变时回调
const onTablePageChange2 = (page: TableDemoPageType) => {
  state.tableData2.param.pageNum = page.pageNum
  state.tableData2.param.pageSize = page.pageSize
  getTableData2()
}

//报修
const repairApplication = () => {
  dialogVisible.value = !dialogVisible.value
}
const cancelRepair = () => {
  dialogVisible.value = !dialogVisible.value
}
const submitRepair = () => {
  dialogVisible.value = !dialogVisible.value
  getTableData()
}

//维修转交(单个)
const transmitDialog = ref(false)
const primaryForm = ref({})
const transmitTask = (row: any) => {
  primaryForm.value = row
  transmitDialog.value = !transmitDialog.value
}
const closeTransmit = () => {
  transmitDialog.value = !transmitDialog.value
}

const submitTransmit = () => {
  transmitDialog.value = !transmitDialog.value
  getTableData()
}

//批量转交
const transmitMoreDialog = ref(false)
const primaryMoreForm = ref({})
const batchTransmit = (row: any) => {
  primaryMoreForm.value = row
  transmitMoreDialog.value = !transmitMoreDialog.value
}
const closeMoreTransmit = () => {
  transmitMoreDialog.value = !transmitMoreDialog.value
}
const submitMoreTransmit = () => {
  transmitMoreDialog.value = !transmitMoreDialog.value
  getTableData()
}

//转交记录
const transmitRecord = (row: any) => {
  router.push({
    name: 'orderTransmitRecord'
  })
}

const handleClick = (tab: TabsPaneContext, event: Event) => {
  // console.log(tab, event);
}

const detailRepair = (row: any) => {
  router.push({
    name: 'repairOrderDetail',
    query: {
      id: row.id,
      type: 'detail',
      form: 1
    }
  })
}
const detailRepair2 = (row: any) => {
  router.push({
    name: 'repairOrderDetail',
    query: {
      id: row.id,
      type: 'detail',
      from: 2
    }
  })
}

const delRepair = (row: any) => {
  ElMessageBox.confirm('确定删除该条内容吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      deleteRepairApi(row.id).then((res) => {
        if (res.code == 0) {
          ElMessage({
            type: 'success',
            message: '删除成功'
          })
          getTableData()
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败'
      })
    })
}
const delRepair2 = (row: any) => {
  ElMessageBox.confirm('确定删除该条内容吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      deleteRepairApi(row.id).then((res) => {
        if (res.code == 0) {
          ElMessage({
            type: 'success',
            message: '删除成功'
          })
          getTableData2()
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败'
      })
    })
}

const closeDialog = ref(false)
const closeId = ref('')
//关闭维修
const closeRepair = (row: any) => {
  closeId.value = row.id
  closeDialog.value = !closeDialog.value
}
const closeCancel = () => {
  closeDialog.value = !closeDialog.value
}

const closeSubmit = () => {
  closeDialog.value = !closeDialog.value
  getTableData()
}

const verifyRepair = (row: any) => {
  router.push({
    name: 'repairOrderDetail',
    query: {
      id: row.id,
      type: 'verify'
    }
  })
}

const entryRepair = (row: any) => {
  router.push({
    name: 'subcontractingAndEntry',
    query: {
      id: row.repairOrderNum,
      wxId: row.id
    }
  })
}

const subcontracting = () => {
  router.push({
    name: 'subcontractingAndEntry',
    query: {
      id: '',
      wxId: ''
    }
  })
}
const subcontracting2 = (row: any) => {
  ElMessageBox.confirm('转为委外维修后,将形成新的维修工单', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      router.push({
        name: 'subcontractingAndEntry',
        query: {
          id: row.repairOrderNum,
          wxId: row.id,
          change: 'change'
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '已取消'
      })
    })
}

let timer: any = null
const batchExport = () => {
  timer && clearTimeout(timer)
  timer = setTimeout(() => {
    if (list.value.length == 0) {
      ElMessage.warning('暂无数据可导出')
      state.search2.btn[0].loading = false
    } else {
      repairBatchReportApi(daochuObj.value).then((res) => {
        if (res.code == 0) {
          ElMessage.success('导出成功,请在下载中心查看')
        }
      })
    }
  }, 1000)
}

let timer2: any = null
const exportRecords = (row: any) => {
  timer2 && clearTimeout(timer2)
  timer2 = setTimeout(() => {
    repairBatchReportApi({ repairId: row.id }).then((res) => {
      if (res.code == 0) {
        ElMessage.success('导出成功,请在下载中心查看')
        state.tableData2.columnBtn[1].loading = false
      } else {
        state.tableData2.columnBtn[1].loading = false
      }
    })
  }, 1000)
}

//定义方法对象 注意定义的方法 必须在上面已经申明 所以建议objFun申明和 listenClick方法 写在页面最下面
const objFun = {
  repairApplication: repairApplication,
  detailRepair: detailRepair,
  delRepair: delRepair,
  closeRepair: closeRepair,
  verifyRepair: verifyRepair,
  entryRepair: entryRepair,
  subcontracting: subcontracting,
  transmitTask: transmitTask
}
// 监听子级表格  传过来的方法
const listenClick = (name: string, val: any) => {
  objFun[name](val)
}
//定义方法对象 注意定义的方法 必须在上面已经申明 所以建议objFun申明和 listenClick方法 写在页面最下面
const objFun2 = {
  detailRepair: detailRepair2,
  exportRecords: exportRecords,
  delRepair: delRepair2,
  subcontracting2: subcontracting2,
  batchExport: batchExport
}
// 监听子级表格  传过来的方法
const listenClick2 = (name: string, val: any) => {
  objFun2[name](val)
}

// 页面加载时
onMounted(() => {
  getTableData()
  getTableData2()
  menu.forEach(async (element: any) => {
    if (element.menuUrl == '/repair/Order') {
      let res = await getButtonListByRoleApi({
        terminalType: 1,
        menuPid: element.id
      })
      res.data.forEach((item: any) => {
        buttonCodes.value.push(item.buttonCode)
      })
    }
  })
})
</script>
<style lang="scss" scoped>
.sreachItem {
  width: 350px;
  margin-bottom: 10px;
}
</style>
<style>
.el-button--primary.is-plain {
  --el-button-bg-color: #ffffff;
  --el-button-hover-text-color: var(--el-color-primary);
  --el-button-hover-bg-color: #ffffff;
}

.el-button--primary.is-plain:hover {
  --el-button-hover-text-color: #fff;
  --el-button-hover-bg-color: var(--el-color-primary);
}

.el-button--warning.is-plain {
  --el-button-bg-color: #fdf6ec;
  --el-button-hover-text-color: #e6a23c;
  --el-button-hover-bg-color: #fdf6ec;
}

.el-button--warning.is-plain:hover {
  --el-button-hover-text-color: #fff;
  --el-button-hover-bg-color: #e6a23c;
}

.el-button--danger.is-plain {
  --el-button-bg-color: #fef0f0;
  --el-button-hover-text-color: #f56c6c;
  --el-button-hover-bg-color: #fef0f0;
}

.el-button--danger.is-plain:hover {
  --el-button-hover-text-color: #fff;
  --el-button-hover-bg-color: #f56c6c;
}
</style>
